package com.tanhua.server.interceptor;

import com.tanhua.model.domain.User;

/*
 * 工具类
 * 对ThreadLocal实现存储数据方法
 * */
public class UserHolder {
    //创建一个ThreadLocal对象
    private static ThreadLocal<User> t1 = new ThreadLocal<>();

    //将用户对象，存入ThreadLocal
    public static void set(User user) {
        t1.set(user);
    }

    //从当前线程，获取用户对象
    public static User get() {
        return t1.get();
    }

    //从当前线程，获取用户对象id
    public static Long getUserId() {
        return t1.get().getId();
    }

    //从当前线程，获取手机号
    public static String getMobile() {
        return t1.get().getMobile();
    }

    //清空
    public static void remove() {
        t1.remove();
    }
}
